home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 July / macformat-026.iso / mac / Shareware City / Developers / SoundMate Plug-In Kit / End.π ƒ / End.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-21  |  2.9 KB  |  134 lines  |  [TEXT/KAHL]

  1. /*****
  2.  * End.c
  3.  *
  4.  *    SoundEditor: Copyright (c) 1993 by
  5.  *
  6.  *    Motion Works Corp.
  7.  *    #130 - 1020 Mainland Street
  8.  *    Vancouver, BC
  9.  *    (604) 685-9975
  10.  *
  11.  *  Author:    DMS        (21DEC93)
  12.  *
  13.  *    End sound effect (SE) component source for Marvin's Modulator
  14.  *
  15.  *****/
  16.  
  17. #include <MacHeaders>
  18. #include <QuickTimeComponents.h>
  19.  
  20.     // prototype
  21.  
  22. pascal ComponentResult _SEWorksOnSelectionOnly(    Boolean *answer );
  23.  
  24. pascal ComponentResult _SEDoEffect( Handle theSound,
  25.                                     Size *selectionStart, Size *selectionEnd,
  26.                                     Handle *newSound,
  27.                                     Size *insertStart, Size *deleteEnd );
  28.  
  29. static SoundHeaderPtr _GetTheSoundHeader( Handle theSound );
  30.  
  31.  
  32. /***
  33.  * _SEWorksOnSelectionOnly
  34.  *
  35.  *        returns TRUE to signify that it should only be enabled when there is a selection
  36.  *
  37.  ***/
  38.  
  39. pascal ComponentResult _SEWorksOnSelectionOnly(    Boolean *answer )
  40. {
  41.     *answer = FALSE;
  42.     
  43.     return noErr;
  44. }
  45.  
  46.  
  47.  
  48. /***
  49.  * _SEEffect
  50.  *
  51.  *        Reverse the selected samples and return a new sound with those samples in it.
  52.  *
  53.  ***/
  54.  
  55. pascal ComponentResult _SEDoEffect(    Handle theSound,
  56.                                     Size *selectionStart, Size *selectionEnd,
  57.                                     Handle *newSound,
  58.                                     Size *insertStart, Size *deleteEnd )
  59. {
  60.     ComponentResult     result = noErr;
  61.     char                theSoundState;
  62.     SoundHeaderPtr        theSoundHeaderPtr;
  63.  
  64.     theSoundState = HGetState( theSound );
  65.     HLock( theSound );
  66.  
  67.     theSoundHeaderPtr = _GetTheSoundHeader( theSound );
  68.  
  69.         // set selection point to the end
  70.         
  71.     if ( theSoundHeaderPtr->encode == stdSH )
  72.     {
  73.         *selectionStart = *selectionEnd = theSoundHeaderPtr->length - 1;
  74.     }
  75.     else if ( theSoundHeaderPtr->encode == extSH )
  76.     {
  77.         *selectionStart = *selectionEnd
  78.             = ((ExtSoundHeaderPtr)theSoundHeaderPtr)->numFrames;
  79.     }
  80.     else if ( theSoundHeaderPtr->encode == cmpSH  )
  81.     {
  82.         *selectionStart = *selectionEnd
  83.             = ((CmpSoundHeaderPtr)theSoundHeaderPtr)->numFrames;
  84.     }
  85.  
  86.     HSetState( theSound, theSoundState );
  87.     
  88.         // don't delete any samples
  89.     *insertStart = *deleteEnd = 0;
  90.     
  91.         // no new sound to insert
  92.     *newSound = NULL;
  93.     
  94.     return result;
  95. }
  96.  
  97.  
  98.  
  99. /**
  100.  * _GetSoundHeader
  101.  *
  102.  *    Return a pointer to the SoundHeader. The sound handle must be locked
  103.  *    while the pointer is in use.
  104.  *
  105.  **/
  106. static SoundHeaderPtr _GetTheSoundHeader( Handle theSound )
  107. {
  108.     Ptr        sndData = *theSound;                            // it's locked by now
  109.     Ptr        cmd;
  110.     short    numSynth;    // should be only one
  111.     short    numCmds;    // should be only one
  112.     short    cmdType;
  113.  
  114.     if ( *((short*)sndData) == 1 )                            // format 1
  115.     {
  116.         numSynth = *((short*)(sndData + 2));
  117.         numCmds = *((short*)(sndData + numSynth * 6 + 4));    // 6 bytes per synth + 4 others
  118.         cmd = sndData + numSynth * 6 + 4 + 2;    
  119.     }
  120.     else if ( *sndData == 2 )                                // format 2
  121.     {
  122.         numCmds = *((short *)(sndData + 4));                // 4 others
  123.         cmd = sndData + 6;    
  124.     }
  125.     else
  126.         return NULL;
  127.  
  128.     cmdType = *((short *)cmd) & 0x7FFF;
  129.     if ( cmdType != bufferCmd && cmdType != soundCmd )
  130.         return NULL;                                        // buffer cmd only
  131.  
  132.     return (SoundHeaderPtr)(sndData + *((long*)(cmd + 4)));    // param 2 == offset to data
  133. }
  134.